package com.company.笔试.sort;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.apache.commons.lang.ObjectUtils;

import java.util.*;

/**
 * @Classname Main
 * @Description TODO
 * @Date 2021/9/11 10:06
 * @Created by ylr
 */
@Data
class User{
    private Integer id;
    private Integer age;
}


public class Main {
    public static void main(String[] args) {



//        PriorityQueue<User> queue = new PriorityQueue<>(new Comparator<User>() {
//            @Override
//            public int compare(User o1, User o2) {
//                return o1.getAge() - o2.getAge();
//            }
//        });

        ArrayList<User> users = new ArrayList<>();
        Integer[][] bitmap = new Integer[100][];

        for (int i = 0; i < 1000000; i++) {
            User user = new User();
            Random random = new Random();
            random.setSeed(i+1);
            user.setId(i);
            user.setAge(random.nextInt(100));
            users.add(user);
        }


        for (User user : users) {
            Integer[] u = bitmap[user.getAge()];
            Integer id = user.getId();
            ArrayList<Integer> integers = new ArrayList<>();
            if (!ObjectUtil.isEmpty(u)){
                integers.addAll(Arrays.asList(u));
            }

            integers.add(id);
            bitmap[user.getAge()] = (Integer[]) integers.toArray();


        }

        int i = 0;
        for (Integer[] integers : bitmap) {
            for (Integer integer : integers) {
                User user = users.get(integer);
                System.out.println(i+" 岁用户有:" + JSON.toJSONString(user));

            }
            i++;
        }
//        User peek = queue.peek();
//        System.out.println(peek);

    }

}
